<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    @close="closeDialog()"
    :visible.sync="visible">
    <ftp-component v-if="addOrUpdateFtpVisible" ref="addOrUpdateFtp" @refreshData="refreshData" @disvisible="disvisible"></ftp-component>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="checkFtpStatus()">FTP状态检查</el-button>
      <el-button type="primary" @click="dataFormSubmit()" v-if="canSubmit">确定</el-button>
    </span>
  </el-dialog>
  
</template>

<script>
    import {getFtpInfoById, addFtpInfo, putObj, checkFtpStatus} from '@/api/gather/configftp'
    import FtpComponent from './configftp-component'

    export default {
    data () {
      return {
        visible: false,
        canSubmit: false,
        addOrUpdateFtpVisible: false,
        dataForm: {}
      }
    },
    components: {
      FtpComponent
    },
    methods: {
      init (id) {
        this.visible = true;
        this.canSubmit = true;
        this.addOrUpdateFtpVisible = true;
        this.$nextTick(() => {
          this.$refs.addOrUpdateFtp.init(id)
        })
      },
      disvisible () {
        this.visible = false
      },
      checkFtpStatus () {
        this.$refs.addOrUpdateFtp.checkFtpStatus()
      },
      dataFormSubmit () {
        this.$refs.addOrUpdateFtp.dataFormSubmit()
      },
      refreshData () {
        this.$emit('refreshDataList')
      },
      //重置表单
      closeDialog() {
         this.$refs.addOrUpdateFtp.closeDialog()
      }
    }
  }
</script>
